package Tela;

import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JPanel;

/**
 *
 * @author Douglas
 */
public final class Pixel extends JPanel {

    int ligado;

    public Pixel() {
        this(0);
    }

    public Pixel(int ligado) {
        this.ligado = ligado;
        this.setColor();
        this.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (isLigado()) {
                    setLigado(0);
                } else {
                    setLigado(1);
                }
                setColor();
            }
        });
    }

    public void setColor() {
        if (isLigado()) {
            this.setBackground(Color.BLACK);
        } else {
            this.setBackground(Color.WHITE);
        }
    }

    public void setLigado(int ligado) {
        this.ligado = ligado;
        setColor();
    }

    public boolean isLigado() {
        if (ligado == 1) {
            return true;
        }
        return false;
    }
    
    public int getLigado(){
        return ligado;
    }
}
